package com.itheima.app.controller;

import com.itheima.app.manager.UserLikeManager;
import com.itheima.vo.UserLikeCountVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
public class UserLikeController {

    @Autowired
    UserLikeManager userLikeManager;

    @GetMapping("/users/counts")
    //互相喜欢，喜欢，粉丝 - 统计
    public UserLikeCountVo counts() {
        return userLikeManager.counts();
    }

    //喜欢，粉丝，互相喜欢详情
    @GetMapping("/users/friends/{type}")
    public ResponseEntity LikeByPage(@PathVariable String type,
                                     @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
                                     @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        return userLikeManager.LikeByPage(type, pageNum, pageSize);
    }

    //粉丝 - 喜欢
    @PostMapping("/users/fans/{uid}")
    public void like(@PathVariable String uid){
        userLikeManager.like(uid);
    }

    //喜欢 - 取消
    @DeleteMapping("/users/like/{uid}")
    public void deleteLike(@PathVariable String uid){
        long likeUserId = Long.parseLong(uid);
        userLikeManager.removeLove(likeUserId);
    }
}
